define(function (required, exports, modules) {
  var modal = require('mods/modal');
  exports.member_down = function (ols) {
    $("." + ols).dropdown({
      on: "hover"
    });
  };

  exports.member_exchange = function () {

    $(".member-exchange").click(function () {
      if ($(this).hasClass("disabled")) {
        modal.alert("系统正在处理中~~~,请不要重复请求");
        return false
      }

      var good_id = $("input[name=exchange-good]").val()
      var _crsf = $("#csrf").val()
      var member_id = $('input[name=member-id]').val()

      if (good_id.length < 1) {
        modal.alert("请选择需要兑换的商品")
        return false
      }
      $(this).addClass("disabled")
      $.ajax({
        url: '/admin/member/exchange-goods',
        type: 'POST',
        dataType: 'json',
        data: {
          good_id: good_id,
          member_id: member_id,
          _csrf: _crsf
        },
        success: function (res) {
          $(this).removeClass("disabled")
          if (res.code == 200) {
            modal.msg(res.msg, {}, function () {
              location.href = "/admin/member/index"
            })
          } else {
            modal.msg(res.msg, {}, function () {
              location.reload()
              return false
            })
          }
        }
      })
    });

    if ($("input[name=get-goods]").val() == '0') {
      modal.msg('此用户积分不足,兑换任何商品', {}, function () {
        location.href = '/admin/member/index'
      });
    }
    ;
  };
})